package org.cklxh.apn;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;

/**
 * 获得APN类型
 * 
 * 切换接入点参考：http://blog.csdn.net/zaqiao/article/details/6966166
 * 				http://blog.csdn.net/liujian885/article/details/5656350
 * 
 * 
 */
public class ApnServer {

	private static Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");

	/**
	 * get 正在使用的Apn
	 * 
	 * @param context
	 * @return
	 */
	public ApnPojo getActiveApn(ContentResolver contextResolver) {
		ApnPojo apnPojo=null;
		
		Cursor c = contextResolver.query(PREFERRED_APN_URI, null,null, null, null);
		if(c!=null && c.moveToFirst()){
			apnPojo=new ApnPojo();
			
			int id = c.getInt(c.getColumnIndex("_id"));
			String name = c.getString(c.getColumnIndex("name"));
			String apn = c.getString(c.getColumnIndex("apn"));
			String proxyHost = c.getString(c.getColumnIndex("proxy"));
			int proxyPort = c.getInt(c.getColumnIndex("port"));
			String username = c.getString(c.getColumnIndex("user"));
			String password = c.getString(c.getColumnIndex("password"));
			
			apnPojo.setId(id);
			apnPojo.setName(name);
			apnPojo.setApn(apn);
			apnPojo.setProxyIsa(proxyHost, proxyPort);
			apnPojo.setProxyAi(username, password);
			
		}
		return apnPojo;
	}

}